package test_achieve.admin;

import constant.Constant;
import util.tools.BusinessTools;
import util.tools.CommonTools;
import cucumber.api.java.en.Given;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

/**
 * Created by chenkuo on 2017/6/19.
 */
public class Login_Admin {

    @Given("^s进入登录界面$")
    public void EnterAdminLoginInter () throws Exception {
        Constant.driverWeb.get(Constant.adminLoginURL);
        CommonTools.waitElementLoad(Constant.driverWeb,"xpath","//*[@id=\"login\"]/div/form/div[1]/div/input");
    }
    @Given("^s输入后台账户名和密码$")
    public void EnterAdminAccountNamePassword () {
        WebElement AdminUser = Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[1]/div/input"));
        AdminUser.sendKeys(Constant.SYSTEMUSER);
        WebElement AdminPassword = Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[2]/div/input"));
        AdminPassword.sendKeys(Constant.SYSTEMPASSWORD);
    }
    @Given("s输入后台账户名:(.+)")
    public void EnterAdminAccountName (String adminUser) {
        WebElement AdminUser = Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[1]/div/input"));
        AdminUser.sendKeys(adminUser);
        WebElement AdminPassword = Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[2]/div/input"));
        AdminPassword.sendKeys("123456");
    }

    @Given("^s获取并输入验证码")
    public void GetEnterPicCaptcha () throws InterruptedException {
        WebElement GetVerificationCode = Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[3]/label[2]/input"));
        GetVerificationCode.sendKeys(BusinessTools.buildPicCaptcha());
    }
    @Given("^s点击登录按钮")
    public void ClickAdminLoginButton () throws InterruptedException {
        Constant.driverWeb.findElement(By.xpath("//*[@id=\"login\"]/div/form/div[4]")).click();
        Thread.sleep(1000);
        Constant.driverWeb.findElement(By.xpath("/html/body/div[3]/div/div/div[2]/div[2]/div/div/div/button[1]")).click();
    }
    @Given("^s登录成功")
    public void CheckAdminLoginSuccess () {
//        System.out.println("CheckAdminLoginSuccessful");
    }

}

